package com.ruoyi.common.utils.parameter;
import java.util.Random;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * 	距离转换
 * @author DEREK
 *
 */
public class DistanceUtil {

	public static void main(String[] args) {
		//        System.out.println(getDistance(113.002397,28.116069,113.002566,28.116632));
		//System.out.println(transferDistance(261311));
		for (int i = 0; i < 20; i++) {
			Random r =new Random();
			System.out.println(r.nextInt(20)+1);
		}
		
	}
	/**
	 * 计算两个经纬度之间的距离 返回字符串
	 *
	 * @param lat1
	 * @param lng1
	 * @param lat2
	 * @param lng2
	 */
	public static String getDistanceStr(double lat1, double lng1, double lat2, double lng2) {
		return transferDistance(getDistance(lat1,lng1,lat2,lng2));
	}

	public static double getDistance(double longitudeFrom, double latitudeFrom, double longitudeTo, double latitudeTo) {
		GlobalCoordinates source = new GlobalCoordinates(latitudeFrom, longitudeFrom);
		GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo);

		return new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target).getEllipsoidalDistance();
	}


	public static String transferDistance(double distance){
		if(distance>=0&& distance<1000) {
			return  String.format("%.0f", distance)+"m";
		}else if(distance >= 1000 && distance <= 10000000){
			return  String.format("%.0f", Math.rint(distance/100)/10)+"km";
		}else {
			return "未知";
		}
	}

	/**
	 * 	获取虚拟距离
	 * @return
	 */
	public static String getVirtuallyDistance() {
		Random r =new Random();
		int i = (r.nextInt(20)+1);
		return i+"km";
	}

}
